home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 476-500 / disk_487 / pprint / source / output.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  8KB  |  307 lines

  1. /************************************************************************
  2. *                                                                                                *
  3. *        output                                                                                *
  4. *                                                                                                *
  5. *-----------------------------------------------------------------------*
  6. *                                                                                                *
  7. *        Module containing the basic screen output routines for the text.    *
  8. *                                                                                                *
  9. ************************************************************************/
  10.  
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <intuition/intuition.h>
  14. #include <libraries/dos.h>
  15. #include <libraries/dosextens.h>
  16. #include <libraries/reqbase.h>
  17. #include <private/help.h>
  18.  
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21. #include <proto/intuition.h>
  22. #include <proto/graphics.h>
  23. #include <proto/reqproto.h>
  24.  
  25. #include    "settings.h"
  26. #include "tops.h"
  27.  
  28. /***************************************
  29.  
  30.                     Definitions
  31.  
  32. ***************************************/
  33.  
  34. #define    RP            ( FirstWindow->RPort )
  35.  
  36. /***************************************
  37.  
  38.                 External References
  39.  
  40. ***************************************/
  41. /***************************************
  42.                     Functions
  43. ***************************************/
  44.  
  45. IMPORT    VOID            RefreshTSize( VOID );
  46. IMPORT    VOID            RefreshRMarg( VOID );
  47. IMPORT    VOID            RefreshLMarg( VOID );
  48. IMPORT    VOID            RefreshPLength( VOID );
  49. IMPORT    VOID            RefreshPWidth( VOID );
  50. IMPORT    VOID            DoRefresh( VOID );
  51. IMPORT    VOID            InitText( VOID );
  52.  
  53. /***************************************
  54.                     Variables
  55. ***************************************/
  56.  
  57. IMPORT    struct Window                  *FirstWindow;
  58.  
  59. IMPORT    UBYTE                                LoadString[];
  60. IMPORT    struct FileInfoBlock          *FIB;
  61. IMPORT    UBYTE                                Dir[],
  62.                                                 File[],
  63.                                                 Path[];
  64. IMPORT    struct FileRequester            FReq;
  65.  
  66. IMPORT    LONG                                Memsize;
  67. IMPORT    UBYTE                              *ActFile;
  68.  
  69. IMPORT    struct Settings                Sets[];
  70. IMPORT    SHORT                                ActSet;
  71. IMPORT    UBYTE                                ScTitle[];
  72.  
  73. IMPORT    UBYTE                                LineBuf[];
  74. IMPORT    SHORT                                Topline;
  75.  
  76. IMPORT    UBYTE                              *HashTab[];
  77. IMPORT    SHORT                                NumLines;
  78. IMPORT    USHORT                            OTSize;
  79.  
  80. /***************************************
  81.  
  82.                     Declarations
  83.  
  84. ***************************************/
  85.  
  86. VOID                        ShowText( SHORT );
  87. UBYTE                      *ConvertLine( UBYTE *, SHORT );
  88. VOID                        PutLine( UBYTE *, SHORT );
  89. static UBYTE          *SkipLine( UBYTE * );
  90. VOID                        InitText( VOID );
  91.  
  92. /************************************************************************
  93. *                                                                                                *
  94. *        ShowText                                                                                *
  95. *                                                                                                *
  96. *-----------------------------------------------------------------------*
  97. *                                                                                                *
  98. *        Routine for displaying the text.                                                *
  99. *                                                                                                *
  100. *-----------------------------------------------------------------------*
  101. *                                                                                                *
  102. *        Parameters        :                                                                    *
  103. *            num            :    First line to show, or -1 for no changes            *
  104. *                                                                                                *
  105. *        Returns            :                                                                    *
  106. *            none                                                                                *
  107. *                                                                                                *
  108. ************************************************************************/
  109.  
  110. VOID        ShowText( SHORT num )
  111. {
  112.     SHORT            i;
  113.     UBYTE          *p;
  114.  
  115.     /***/
  116.  
  117.     if( ActFile == NULL )
  118.     {
  119.         SetAPen( RP, 0 );
  120.         RectFill( RP, 0L,0L, 640L,( LONG )( LAYOUT_TOP - 1 ));
  121.         SetAPen( RP, 1 );
  122.         Topline    =    0;
  123.         return;
  124.     }
  125.     if( num > ( NumLines - NUM_LINES ))
  126.         num    =    NumLines - NUM_LINES;
  127.     if( num < 0 )
  128.         num    =    0;
  129.     if(( num == Topline )&&( OTSize == Sets[ ActSet].Tabsize ))
  130.     {
  131.         ClearIDCMP( FirstWindow );
  132.         return;
  133.     }
  134.     p    =    HashTab[num];
  135.     for( i = 0; i < NUM_LINES; i++ )
  136.     {
  137.         p    =    ConvertLine( p, Sets[ ActSet ].Tabsize );
  138.         PutLine( LineBuf, i );
  139.     }
  140.     Topline    =    num;
  141. }
  142.  
  143. /************************************************************************
  144. *                                                                                                *
  145. *        ConvertLine                                                                            *
  146. *                                                                                                *
  147. *-----------------------------------------------------------------------*
  148. *                                                                                                *
  149. *        Converts a line of text for screen output.                                *
  150. *                                                                                                *
  151. *-----------------------------------------------------------------------*
  152. *                                                                                                *
  153. *        Parameters        :                                                                    *
  154. *            p                :    Pointer to the beginning of the line.                *
  155. *            TS                :    Tabsize                                                        *
  156. *                                                                                                *
  157. *        Returns            :                                                                    *
  158. *            Pointer to the beginning of the next line.                            *
  159. *                                                                                                *
  160. ************************************************************************/
  161.  
  162. UBYTE      *ConvertLine( UBYTE *p, SHORT TS )
  163. {
  164.     SHORT            i,
  165.                     j,
  166.                     nt;
  167.     UBYTE          *q;
  168.  
  169.     /***/
  170.  
  171.     if( TS == 0 )            /* Don't wanna run into a division by zero */
  172.         TS    =    1;
  173.  
  174.     /*    First, delete 80 chars, so that the screen output routines can use
  175.         a constant value for the text length. Then, we find our return value.
  176.         */
  177.  
  178.     for( i = 0; i < 81; i++ )
  179.         LineBuf[i]    =    ' ';
  180.  
  181.     for( q = p;( *q != '\n' )&&( q < ( ActFile + Memsize )); q++ )
  182.         ;
  183.     if( q < ( ActFile + Memsize ))
  184.         q++;
  185.  
  186.     /*    Now, we process the line, using the tab replacing algorithm, we
  187.         developed for "PS". We stop, when we have written 80 characters.
  188.         */
  189.  
  190.     i        =    0;
  191.     while(( p != q )&&( i < 81 ))
  192.     {
  193.         if( *p != '\t' )
  194.             LineBuf[i++]    =    *p++;
  195.         else
  196.         {
  197.             nt    =    TS - ( i % TS );
  198.             for( j = 0; j < nt; j++ )
  199.                 LineBuf[i++]    =    ' ';
  200.             p++;
  201.         }
  202.     }
  203.     i--;
  204.     LineBuf[i]    =    ' ';
  205.     return    q;
  206. }
  207.  
  208. /************************************************************************
  209. *                                                                                                *
  210. *        PutLine                                                                                *
  211. *                                                                                                *
  212. *-----------------------------------------------------------------------*
  213. *                                                                                                *
  214. *        Put a line to the Screen.                                                        *
  215. *                                                                                                *
  216. *-----------------------------------------------------------------------*
  217. *                                                                                                *
  218. *        Parameters        :                                                                    *
  219. *            lpt            :    Pointer to the beginning of the line                *
  220. *            offs            :    Offset from the top.                                        *
  221. *                                                                                                *
  222. *        Returns            :                                                                    *
  223. *            none                                                                                *
  224. *                                                                                                *
  225. ************************************************************************/
  226.  
  227. VOID        PutLine( UBYTE *lpt, SHORT offs )
  228. {
  229.     Move( RP, 0L, ( LONG )( 8 * offs + 17 ));
  230.     Text( RP, lpt, 81 );
  231. }
  232.  
  233. /************************************************************************
  234. *                                                                                                *
  235. *        SkipLine                                                                                *
  236. *                                                                                                *
  237. *-----------------------------------------------------------------------*
  238. *                                                                                                *
  239. *        Skip one line of text                                                            *
  240. *                                                                                                *
  241. *-----------------------------------------------------------------------*
  242. *                                                                                                *
  243. *        Parameters        :                                                                    *
  244. *            p                :    Pointer to the line                                        *
  245. *                                                                                                *
  246. *        Returns            :                                                                    *
  247. *            Pointer to the next line                                                    *
  248. *                                                                                                *
  249. ************************************************************************/
  250.  
  251. static UBYTE      *SkipLine( UBYTE *p )
  252. {
  253.     UBYTE      *q;
  254.  
  255.     /***/
  256.  
  257.     for( q = p;( *q != '\n' )&&( q < ( ActFile + Memsize )); q++ )
  258.         ;
  259.     if( q < ( ActFile + Memsize ))
  260.         q++;
  261.     return    q;
  262. }
  263.  
  264. /************************************************************************
  265. *                                                                                                *
  266. *        InitText                                                                                *
  267. *                                                                                                *
  268. *-----------------------------------------------------------------------*
  269. *                                                                                                *
  270. *        Initialize the hashing table for the line beginnings.                    *
  271. *                                                                                                *
  272. *-----------------------------------------------------------------------*
  273. *                                                                                                *
  274. *        Parameters        :                                                                    *
  275. *            none                                                                                *
  276. *                                                                                                *
  277. *        Returns            :                                                                    *
  278. *            none                                                                                *
  279. *                                                                                                *
  280. *        Globals used    :                                                                    *
  281. *            HashTab                                                                            *
  282. *                                                                                                *
  283. ************************************************************************/
  284.  
  285. VOID        InitText( VOID )
  286. {
  287.     UBYTE          *p;
  288.     SHORT            i;
  289.  
  290.     /***/
  291.  
  292.     if( p    =    ActFile )
  293.     {
  294.         i    =    0;
  295.         while(( p < ( ActFile + Memsize ))&&( i < 5120 ))
  296.         {
  297.             HashTab[i++]    =    p;
  298.             p    =    SkipLine( p );
  299.         }
  300.         NumLines    =    i;
  301.     }
  302.     else
  303.     {
  304.         NumLines    =    0;
  305.     }
  306. }
  307.